using System;
using System.Collections.Generic;
using System.Text;
using Cores;
using System.Data;
using System.Data.SqlClient;

namespace DAOLayer
{
    public class LichChieuDao
    {
        private Connection _conn;

        public Connection Conn
        {
            get { return _conn; }
            set { _conn = value; }
        }
        public LichChieuDao()
        {
            Conn = new Connection();
            if (Conn.Connect().State == ConnectionState.Closed)
            {
                Conn.ConnObj.Open();
            }
        }
        ~LichChieuDao()
        {
            return;
        }

        public DataTable LayLichChieu(int maphim, DateTime ngaybd, DateTime ngaykt)
        {
            SqlCommand cmd = new SqlCommand("SpLayLichChieu", Conn.ConnObj);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@MaPhim", maphim);
            cmd.Parameters.AddWithValue("@NgayBD", ngaybd);
            cmd.Parameters.AddWithValue("@NgayKT", ngaykt);
            DataTable result = new DataTable("LichChieu");
            result.Columns.Add("TenPhim", typeof(string));
            result.Columns.Add("TenRap", typeof(string));
            result.Columns.Add("NgayChieu", typeof(string));
            result.Columns.Add("ThoiGianBD", typeof(string));
            SqlDataReader rd = cmd.ExecuteReader();
            DataRow rows;
            while (rd.Read())
            {
                rows = result.NewRow();
                rows["TenPhim"] = rd.GetString(0);
                rows["TenRap"] = rd.GetString(1);
                DateTime dt = rd.GetDateTime(2);
                rows["NgayChieu"] = dt.ToShortDateString();

                rows["ThoiGianBD"] = rd.GetString(3);
                result.Rows.Add(rows);
            }
            rd.Close();
            Conn.Disconnect();
            return result;
        }
    }
}
